import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'setting_logic.dart';
import 'widget/widget.dart';
import '../../routes/routes.dart';
import '../../shared/shared.dart';
import '../../widgets/widgets.dart';

class SettingPage extends GetView<SettingLogic> {
  const SettingPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        const Background(imageURL: AssetsURL.backgroundPicture1, opacity: 0.59),
        _body()
      ],
    );
  }

  SafeArea _body() {
    return SafeArea(
        child: Scaffold(
            backgroundColor: Colors.transparent,
            body: SingleChildScrollView(
                child: Container(
                    margin: const EdgeInsets.symmetric(horizontal: 30),
                    child: _buildMain()))));
  }

  Column _buildMain() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        _back(),
        CommonWidget.rowHeight(height: 40),
        _selectWidget(),
        _disturbWidget(),
        const SettingOption(text: '消息推送'),
        _exitUser(),
        const SettingOption(text: '关于我们'),
        const SettingOption(text: '常见问题'),
        const SettingOption(text: '评价‘蒙眼旅人’'),
        const SettingOption(text: '开篇动画'),
        const SettingOption(text: '分享'),
        CommonWidget.rowHeight(height: 30),
        const Center(
          child: Text('《用户协议》和《隐私政策》',
              style: TextStyle(color: ColorConstants.themeColor, fontSize: 18)),
        )
      ],
    );
  }

  InkWell _exitUser() {
    return InkWell(
      onTap: () => Get.offAllNamed(Routes.login),
      radius: 0,
      highlightColor: Colors.transparent,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
              margin: const EdgeInsets.symmetric(vertical: 20),
              child: const Text('退出账户',
                  style: TextStyle(
                      color: ColorConstants.themeColor, fontSize: 18))),
          CommonWidget.line()
        ],
      ),
    );
  }

  Column _selectWidget() {
    return Column(
      children: [_musicSwitch(), CommonWidget.line()],
    );
  }

  Column _disturbWidget() {
    return Column(
      children: [_disturbSwitch(), CommonWidget.line()],
    );
  }

  Row _musicSwitch() {
    return Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
      Container(
        margin: const EdgeInsets.symmetric(vertical: 20),
        child: const Text('背景音乐',
            style: TextStyle(color: ColorConstants.themeColor, fontSize: 18)),
      ),
      Obx(() => Switch(
          activeColor: ColorConstants.musicSelect,
          value: controller.music.value,
          onChanged: (value) => controller.changeMusic()))
    ]);
  }

  Row _disturbSwitch() {
    return Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
      Container(
        margin: const EdgeInsets.symmetric(vertical: 20),
        child: const Text('免打扰设置',
            style: TextStyle(color: ColorConstants.themeColor, fontSize: 18)),
      ),
      Obx(() => Switch(
          activeColor: ColorConstants.musicSelect,
          value: controller.doNot.value,
          onChanged: (value) => controller.changeDo()))
    ]);
  }

  IconButton _back() {
    return IconButton(
        onPressed: () => Get.back(),
        icon: const Icon(Icons.arrow_back_ios,
            size: 35, color: ColorConstants.themeColor));
  }
}
